package com.ruoyi.mobile.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.mobile.mapper.ArticleTagRelationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mobile.mapper.TagMapper;
import com.ruoyi.mobile.domain.Tag;
import com.ruoyi.mobile.service.ITagService;

/**
 * 文章标签Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-09-19
 */
@Service
public class TagServiceImpl implements ITagService 
{
    @Autowired
    private TagMapper tagMapper;

    @Autowired
    private ArticleTagRelationMapper articleTagRelationMapper;

    /**
     * 查询文章标签
     * 
     * @param id 文章标签主键
     * @return 文章标签
     */
    @Override
    public Tag selectTagById(Integer id)
    {
        return tagMapper.selectTagById(id);
    }

    /**
     * 查询文章标签列表
     * 
     * @param tag 文章标签
     * @return 文章标签
     */
    @Override
    public List<Tag> selectTagList(Tag tag)
    {
        return tagMapper.selectTagList(tag);
    }

    @Override
    public List<Tag> selectAllTagList() {
        return tagMapper.selectAllTagList();
    }

    @Override
    public List<Integer> selectTagIdsByArticle(Integer articleId) {
        return tagMapper.selectTagIdsByArticle(articleId);
    }

    @Override
    public Integer delTagRelation(Integer articleId) {
        return articleTagRelationMapper.deleteByArticleId(articleId);
    }

    /**
     * 新增文章标签
     * 
     * @param tag 文章标签
     * @return 结果
     */
    @Override
    public int insertTag(Tag tag)
    {
        tag.setCreateTime(DateUtils.getNowDate());
        return tagMapper.insertTag(tag);
    }

    /**
     * 修改文章标签
     * 
     * @param tag 文章标签
     * @return 结果
     */
    @Override
    public int updateTag(Tag tag)
    {
        tag.setUpdateTime(DateUtils.getNowDate());
        return tagMapper.updateTag(tag);
    }

    /**
     * 批量删除文章标签
     * 
     * @param ids 需要删除的文章标签主键
     * @return 结果
     */
    @Override
    public int deleteTagByIds(Integer[] ids)
    {
        return tagMapper.deleteTagByIds(ids);
    }

    /**
     * 删除文章标签信息
     * 
     * @param id 文章标签主键
     * @return 结果
     */
    @Override
    public int deleteTagById(Integer id)
    {
        return tagMapper.deleteTagById(id);
    }
}
